<template>
  <view>
    <view class="add-pic" @click="addCatPic()">
      <image src="../../static/cat-card/cat-detail/group146.png" mode=""></image>
    </view>
  </view>
</template>

<script>
  export default {
    name:"add-catPic",
    data() {
      return {
        
      };
    },
    props:{
      kid:{
        typeof: Number,
        default: 3
      }
    },
    methods:{
      async addCatPic(){
        const res = await uni.chooseImage({
        	count: 1,
        });
        console.log(res);
        const formData = {
          kid: this.kid
        }
        const token = uni.getStorageSync('token')
        const data = await uni.uploadFile({
            url: 'http://www.newbabyya.com/ketty/uploadImg', // 你的后端上传接口  
            filePath: res[1].tempFilePaths[0], // 文件路径  
            name: 'file', 
            method: 'post',
            formData: formData,
            header:{
                   'Authorization': token
                  } 
        }); 
        console.log(JSON.parse(data[1].data));
        if(JSON.parse(data[1].data).code === 200) return uni.$showMsg('上传猫咪照片成功！')
      }
    }
  }
</script>

<style lang="scss">
.add-pic{
  position: fixed;
  right: 25rpx;
  bottom: 50rpx;
  image{
    width: 136rpx;
    height: 136rpx;
    
  }
}
</style>